#include <algorithm>
#include <cstdio>
#define N 110
#define INF 0x7fffffff
using namespace std;
int len = 0;
int f[N][N];
char a[N];
void init() {
	for (int i = 1; i <= len; ++i) {
		for (int j = 1; j <= len; ++j) {
			if (i < j) {
				f[i][j] = INF;
			} else if (i == j) {
				f[i][j] = 1;
			}
		}
	}
}
int main() {
	freopen("testdata.in", "r", stdin);
	freopen("testdata.out", "w", stdout);
	int c;
	while ((c = getchar()) && (c == '(' || c == ')' || c == '[' || c == ']')) {
		a[++len] = c;
	}
	init();
	for (int i = 2; i <= len; ++i) {
		for (int l = 1; l <= len - i + 1; ++l) {
			int r = l + i - 1;
			if ((a[l] == '(' && a[r] == ')') || (a[l] == '[' && a[r] == ']')) {
				f[l][r] = min(f[l + 1][r - 1], f[l][r]);
			}
			for (int k = l; k < r; ++k) {
				f[l][r] = min(f[l][r], f[l][k] + f[k + 1][r]);
			}
		}
	}
	printf("%d", f[1][len]);
	fclose(stdin);
	fclose(stdout);
	return 0;
}